package com.atguigu.lease.web.admin.schedule;

import com.atguigu.lease.model.entity.LeaseAgreement;
import com.atguigu.lease.model.enums.LeaseStatus;
import com.atguigu.lease.web.admin.service.LeaseAgreementService;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.conditions.update.LambdaUpdateWrapper;
import org.checkerframework.checker.units.qual.C;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.scheduling.annotation.Scheduled;
import org.springframework.stereotype.Component;

import java.util.Date;


@Component
public class ScheduledTasks {
    @Autowired
    LeaseAgreementService leaseAgreementService;

    @Scheduled(cron = "0 43 15 * * *")
    public void scheduledTasks() {
        Date date = new java.util.Date();
        leaseAgreementService.update(new LambdaUpdateWrapper<LeaseAgreement>()
                .le(LeaseAgreement::getLeaseEndDate, date)
                .in(LeaseAgreement::getStatus, LeaseStatus.WITHDRAWING, LeaseStatus.SIGNED).
                set(LeaseAgreement::getStatus, LeaseStatus.EXPIRED));
    }
}
